<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>添加进场单</title>
    <link href="../img/icon.ico" rel="shortcut icon" />
    <link rel="stylesheet" href="../layui/css/layui.css" />
    <link rel="stylesheet" href="../css/element.min.css?1" />
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_2315128_5bb2ydgeqs.css">
    <link rel="stylesheet" href="../css/reset.css?3133">
    <link rel="stylesheet" href="../css/setlayui.css?12">
    <link rel="stylesheet" href="../css/viewer.min.css">
    <script src="../layui/layui.all.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/vue.min.js"></script>
    <script type="text/javascript" src="../js/element.min.js"></script>
    <script src="../js/viewer.min.js"></script>
</head>

<body>
    <div id="app" class="page-container" style="display: none;" v-show="showApp">
        <!-- <el-input placeholder="请输入内容" min="0" type="number" v-model="testNumber" clearable @change="validateTextNumber">
        </el-input> -->
        <div class="contetn_box">
            <div class="top_box">
                <div class="cell_box" style="width: 43.84vw;">
                    <div class="cell_title">
                        <div class="cell_name">基本信息:</div>
                        <div class="cell_but"></div>
                    </div>
                    <div class="cell_cont" style="height: 378px;">
                        <div class="form_box" style="margin-top: 0;">
                            <div class="form_name">进场单号</div>
                            <div class="form_cont" style="color:#FA7355;">保存后自动生成</div>
                        </div>

                        <div class="form_box">
                            <div class="form_name must_input">供应商</div>
                            <div class="form_cont" style="padding-right: 10px;">
                                <el-tooltip class="item" effect="dark" :disabled="!supplier.supplierName"
                                    :content="supplier.supplierName" placement="top">
                                    <el-input disabled class="public_input" placeholder="请选择供应商"
                                        v-model="supplier.supplierName"></el-input>
                                </el-tooltip>
                            </div>
                            <div class="form_but" style="width: 62px;">
                                <el-button
                                    v-if="radio != 2 || !contract.contractId || (contract.contractId && (!supplier.supplierId || supplier.supplierId < 0))"
                                    @click="chioceGys" class="border_but" type="primary">选择</el-button>
                            </div>
                        </div>
                        <div class="form_box">
                            <div class="form_name">备注</div>
                            <div class="form_cont" style="padding-right: 10px;">
                                <el-tooltip class="item" effect="dark" :disabled="!remarks" :content="remarks"
                                    placement="top">
                                    <el-input type="textarea" :rows="3" placeholder="请输入" v-model="remarks"></el-input>
                                </el-tooltip>
                            </div>
                            <div class="form_but" style="width: 62px;">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="cell_box" style="width: 46.94vw;float: right;">
                    <div class="cell_title">
                        <div class="cell_name">现场抓拍:</div>
                        <div class="cell_but">
                            <el-button @click="chioceGlimg" class="border_but" type="primary">关联</el-button>
                        </div>
                    </div>
                    <div class="cell_cont" style="height: 378px; padding: 0 1.67vw;">
                        <div class="file_item">
                            <el-upload action="##" accept="image/*" list-type="picture-card" :show-file-list="false"
                                :http-request="zphttprequest" multiple>
                                <i class="el-icon-plus"></i>
                            </el-upload>
                        </div>
                        <div class="file_item" v-for="(item, index) in glimgList" :key="index"
                            style="border: 2px solid #999999;">
                            <img :src="item.fileurl" alt="">
                            <div class="file_mask">
                                <div @click="prevewImg(item.fileurl)" class="el-icon-zoom-in"></div>
                                <div @click="downImg(item.filename, item.fileurl)" class="el-icon-download"
                                    style="margin: 0 20px;"></div>
                                <div @click="removeImg(glimgList, index)" class="el-icon-delete"></div>
                            </div>
                        </div>
                        <div class="file_item" v-for="(item, index) in listGlchioceImgData" :key="index"
                            style="border: 2px solid #999999;">
                            <img :src="item.fileurl" alt="">
                            <div class="file_mask">
                                <div @click="prevewImg(item.fileurl)" class="el-icon-zoom-in"></div>
                                <div @click="downImg(item.filename, item.fileurl)" class="el-icon-download"
                                    style="margin: 0 20px;"></div>
                            </div>
                        </div>
                        <div class="file_item" v-for="(item, index) in noorderImgData" :key="index"
                            style="border: 2px solid #999999;">
                            <img :src="item.fileurl" alt="">
                            <div class="file_mask">
                                <div @click="prevewImg(item.fileurl)" class="el-icon-zoom-in"></div>
                                <div @click="downImg(item.filename, item.fileurl)" class="el-icon-download"
                                    style="margin: 0 20px;"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="cell_box" style="padding-left: 3.34vw;margin-top: 30px;">
                <div class="cell_title">
                    <div class="cell_name">送货单照片:</div>
                    <div class="cell_but">
                        <el-upload class="upload-demo" action="##" accept="image/*" multiple :show-file-list="false"
                            :http-request="shdhttprequest">
                            <el-button class="border_but" type="primary">上传照片</el-button>
                        </el-upload>
                    </div>
                </div>
                <div class="cell_cont" style="width: 544px;">
                    <div class="table_box border_table_box">
                        <el-table :data="fileList" max-height="400px" border style="width: 100%">

                            <el-table-column prop="filename" align="center" min-width="100" show-overflow-tooltip
                                label="名称"></el-table-column>

                            <el-table-column prop="userName" align="center" show-overflow-tooltip label="上传人"
                                min-width="70">
                            </el-table-column>

                            <el-table-column prop="uploadTime" align="center" show-overflow-tooltip label="上传时间"
                                width="160">
                            </el-table-column>

                            <el-table-column align="center" show-overflow-tooltip label="操作" width="140">
                                <template slot-scope="scope">
                                    <el-button @click="prevewImg(scope.row.fileurl)" type="text">查看</el-button>
                                    <el-button @click="downImg(scope.row.filename, scope.row.fileurl)" type="text">
                                        下载
                                    </el-button>
                                    <el-button @click="removeImg(fileList, scope.$index)" type="text">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </div>
            <div class="cell_box" style="width: 100%; padding:0 1.84vw 0 3.34vw;margin-top: 30px;">
                <div class="cell_title">
                    <div class="cell_name">订单明细:</div>
                    <div class="cell_but">
                        <el-button @click="chioceorder" class="border_but" type="primary">添加订单</el-button>
                    </div>
                </div>
                <div class="cell_cont">
                    <div v-for="(item, index) in allTableData" :key="index">
                        <div class="list_title" style="padding: 10px 0;display: flex;">
                            <div
                                style="display: flex;align-items: center;color:#fff;background: #fa7355;border-radius: 4px;padding: 4px 10px;">
                                <div>采购订单 {{item.orderNo}}</div>
                                <div @click="removeImg(allTableData, index, 1)" class="el-icon-circle-close"
                                    style="margin-left: 20px;cursor: pointer;color:#fff;"></div>
                            </div>
                        </div>
                        <div class="table_box border_table_box" style="margin-bottom: 10px;">
                            <el-table :data="item.clmxList" border style="width: 100%" height="400">

                                <el-table-column prop="materialName" align="center" min-width="100"
                                    show-overflow-tooltip label="名称"></el-table-column>
                                <el-table-column prop="specsName" align="center" show-overflow-tooltip label="规格"
                                    min-width="70">
                                </el-table-column>
                                <el-table-column align="center" show-overflow-tooltip label="生产厂家" min-width="140">
                                    <template slot-scope="scope">
                                        <div style="display: flex;align-items: center;justify-content: center;"
                                            v-if="!scope.row.manufacturerId || scope.row.manufacturerId.length == 0">
                                            <el-button @click="chioceCj(item, scope.row, scope.$index)"
                                                class="border_but" style="height: 24px;margin-right: 0;" type="primary">
                                                选择厂家
                                            </el-button>
                                        </div>
                                        <div @click="chioceCj(item, scope.row, scope.$index)"
                                            style="color: #5574D7;text-decoration: underline;cursor: pointer;"
                                            v-if="scope.row.manufacturerId && scope.row.manufacturerId.length > 0">
                                            {{scope.row.manufacturer}}
                                        </div>
                                    </template>
                                </el-table-column>

                                <el-table-column align="center" show-overflow-tooltip label="进场车牌" min-width="140">
                                    <template slot-scope="scope">
                                        <div style="display: flex;align-items: center;justify-content: center;"
                                            v-if="!scope.row.uuidlicensePlates">
                                            <el-button @click="chioceCpss(index, scope.row, scope.$index)"
                                                class="border_but" style="height: 24px;margin-right: 0;" type="primary">
                                                关联车牌
                                            </el-button>
                                        </div>
                                        <div @click="chioceCpss(index, scope.row, scope.$index)"
                                            style="color: #5574D7;text-decoration: underline;cursor: pointer;"
                                            v-if="scope.row.uuidlicensePlates">{{scope.row.showCpValue}}</div>
                                    </template>
                                </el-table-column>

                                <el-table-column align="center" show-overflow-tooltip label="进场数量" width="160">
                                    <template slot-scope="scope">
                                        <div class="table_input">
                                            <el-input placeholder="请输入内容" :min="0" type="number"
                                                v-model="scope.row.count" clearable></el-input>
                                        </div>
                                    </template>
                                </el-table-column>

                                <el-table-column prop="unit" align="center" show-overflow-tooltip label="单位"
                                    min-width="70">
                                </el-table-column>

                                <el-table-column prop="approachTime" align="center" show-overflow-tooltip label="进场时间"
                                    width="242">
                                    <template slot-scope="scope">
                                        <div class="table_input">
                                            <el-date-picker v-model="scope.row.approachTime" type="datetime"
                                                format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm"
                                                placeholder="选择日期时间">
                                            </el-date-picker>
                                        </div>
                                    </template>
                                </el-table-column>
                                <!-- 存放位置 -->
                                <el-table-column align="center" show-overflow-tooltip label="存放位置" min-width="150">
                                    <template slot-scope="scope">
                                        <div style="display: flex;align-items: center;"
                                            v-if="!scope.row.storageId || scope.row.storageId.length == 0">
                                            <el-button @click="chioceCk(item, scope.row, scope.$index)"
                                                class="border_but" style="height: 24px;margin-right: 0;" type="primary">
                                                选择仓库
                                            </el-button>
                                        </div>
                                        <div @click="chioceCk(item, scope.row, scope.$index)"
                                            style="color: #5574D7;text-decoration: underline;cursor: pointer;"
                                            v-if="scope.row.storageId && scope.row.storageId.length > 0">
                                            {{scope.row.storageName}} <span
                                                v-if="scope.row.goodsShelvesNumber">({{scope.row.goodsShelvesNumber}})</span>
                                        </div>
                                    </template>
                                </el-table-column>

                                <el-table-column align="center" show-overflow-tooltip label="操作" width="106">
                                    <template slot-scope="scope">
                                        <el-button @click="removeImg(item.clmxList, scope.$index, 1)" type="text">
                                            删除
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="cell_box" style="width: 100%; padding:0 1.84vw 0 3.34vw;margin-top: 30px;">
                <div class="cell_title">
                    <div class="cell_name">无订单进场明细:</div>
                    <div class="cell_but">
                        <el-button @click="chioceClmx" class="border_but" type="primary">添加材料</el-button>
                    </div>
                </div>
                <div class="cell_cont">
                    <div class="table_box border_table_box">
                        <el-table :data="clmxList" border style="width: 100%" height="400">

                            <el-table-column prop="materialName" align="center" min-width="100" show-overflow-tooltip
                                label="名称"></el-table-column>

                            <el-table-column prop="specsName" align="center" show-overflow-tooltip label="规格"
                                min-width="70">
                            </el-table-column>

                            <el-table-column align="center" show-overflow-tooltip label="进场车牌" min-width="140">
                                <template slot-scope="scope">
                                    <div style="display: flex;align-items: center;justify-content: center;"
                                        v-if="!scope.row.uuidlicensePlates && scope.row.uuidlicensePlates.trim().length == 0 ">
                                        <el-button @click="chiocenoorderCpss(scope.row, scope.$index)"
                                            class="border_but" style="height: 24px;margin-right: 0;" type="primary">
                                            关联车牌
                                        </el-button>
                                    </div>
                                    <div @click="chiocenoorderCpss(scope.row, scope.$index)"
                                        style="color: #5574D7;text-decoration: underline;cursor: pointer;"
                                        v-if="scope.row.uuidlicensePlates">{{scope.row.showCpValue}}</div>
                                </template>
                            </el-table-column>

                            <el-table-column align="center" show-overflow-tooltip label="进场数量" width="160">
                                <template slot-scope="scope">
                                    <div class="table_input" v-if="scope.row.isAdd">
                                        <el-input placeholder="请输入内容" type="number" :min="0" v-model="scope.row.count"
                                            clearable></el-input>
                                    </div>
                                    <span v-if="!scope.row.isAdd">{{scope.row.count}}</span>
                                </template>
                            </el-table-column>

                            <el-table-column prop="unit" align="center" show-overflow-tooltip label="单位" min-width="70">
                            </el-table-column>

                            <el-table-column prop="approachTime" align="center" show-overflow-tooltip label="进场时间"
                                min-width="242">
                                <template slot-scope="scope">
                                    <div class="table_input">
                                        <el-date-picker v-model="scope.row.approachTime" type="datetime"
                                            format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm"
                                            placeholder="选择日期时间">
                                        </el-date-picker>
                                    </div>
                                </template>
                            </el-table-column>

                            <el-table-column align="center" show-overflow-tooltip label="存放位置" min-width="150">
                                <template slot-scope="scope">
                                    <el-button @click="chioceCk2(scope.row, scope.$index)" v-if="!scope.row.storageId"
                                        class="border_but" style="height: 24px;margin: 0 auto;" type="primary">
                                        选择仓库
                                    </el-button>
                                    <el-button @click="chioceCk2(scope.row, scope.$index)"
                                        v-if="scope.row.isAdd && scope.row.storageId" class="txt_link" type="text">
                                        {{scope.row.storageName}}<span
                                            v-if="scope.row.goodsShelvesNumber.length > 0">({{scope.row.goodsShelvesNumber}})</span>
                                    </el-button>
                                    <span v-if="!scope.row.isAdd && scope.row.storageId">
                                        {{scope.row.storageName}}<span
                                            v-if="scope.row.goodsShelvesNumber.length > 0">({{scope.row.goodsShelvesNumber}})</span>
                                    </span>
                                </template>
                            </el-table-column>

                            <el-table-column align="center" show-overflow-tooltip label="操作" width="106">
                                <template slot-scope="scope">
                                    <el-button @click="removeImg(clmxList, scope.$index, 1)" v-if="scope.row.isAdd"
                                        type="text">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </div>
        </div>
        <div class="but_box">
            <el-button @click="cancels" class="cancelClass">取消</el-button>
            <el-button @click="confirms2" type="primary" style="margin-left: 120px">提交</el-button>
        </div>
        <!-- 订单明细-关联车牌 -->
        <el-dialog title="选择车牌" :visible.sync="dialogVisible" custom-class="public_popup" width="60%">
            <div class="public_popup_box">
                <div class="public_popup_cell_box">
                    <div class="popup_cell_name must_input">输入或选择车牌:</div>
                    <div class="popup_cell_item" v-for="(item, index) in inputcpList" :key="index">
                        <div style="display: flex;">
                            <div class="popup_cell_cont" style="padding-right: 10px;">
                                <el-tooltip class="item" effect="dark" :disabled="!item.licensePlate"
                                    :content="item.licensePlate" placement="top">
                                    <el-input placeholder="请输入内容" v-model="item.licensePlate" class="public_input"
                                        @change="bindCpImg(index)" clearable>
                                    </el-input>
                                </el-tooltip>

                            </div>
                            <div style="display: flex;align-items: center;width: 202px;">
                                <el-button @click="removeImg(inputcpList, index, 1)" v-if="index != 0"
                                    class="border_but" type="primary">删除</el-button>
                                <el-button @click="addCpId(item)" v-if="index == inputcpList.length - 1"
                                    class="border_but" type="primary">新增</el-button>
                                <el-button @click="xzCpimg" v-if="index == inputcpList.length - 1" class="border_but"
                                    type="primary">选择</el-button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="but_box">
                    <el-button @click="dialogVisible = false" class="cancelClass">取消</el-button>
                    <el-button v-if="popupType == 1" type="primary" @click="chioceCpConfirm" style="margin-left: 120px">
                        提交
                    </el-button>
                    <el-button v-if="popupType == 2" type="primary" @click="chioceorderCpConfirm"
                        style="margin-left: 120px">提交</el-button>
                </div>
            </div>
        </el-dialog>
        <!-- 无订单进场的材料需要选择一个合同或输入单价 -->
        <el-dialog title="无订单进场的材料需要选择一个合同或输入单价" :visible.sync="orderdialogVisible" custom-class="public_popup"
            width="80%">
            <div class="public_popup_box">
                <div class="public_popup_cell_box">
                    <div class="creat_order_box">
                        <div class="creat_order_name">关联合同</div>
                        <div class="creat_order_cont" style="margin-left: 20px;">
                            <el-tooltip class="item" effect="dark" :disabled="!noorderHtObj.noorderHtName"
                                :content="noorderHtObj.noorderHtName" placement="top">
                                <el-input placeholder="请输入内容" disabled v-model="noorderHtObj.noorderHtName"
                                    class="public_input" clearable>
                                </el-input>
                            </el-tooltip>

                        </div>
                        <div style="margin-left: 20px;">
                            <el-button @click="chioceht" class="border_but" type="primary">选择</el-button>
                        </div>
                    </div>
                    <div class="creat_order_table table_box border_table_box">
                        <el-table height="100%" :data="creatOrderList" border style="width: 100%">

                            <el-table-column prop="materialName" align="center" min-width="100" show-overflow-tooltip
                                label="名称"></el-table-column>

                            <el-table-column prop="specsName" align="center" show-overflow-tooltip label="规格"
                                min-width="70">
                            </el-table-column>

                            <el-table-column prop="count" align="center" show-overflow-tooltip label="进场数量" width="120">
                            </el-table-column>

                            <el-table-column prop="unit" align="center" show-overflow-tooltip label="单位" min-width="70">
                            </el-table-column>

                            <el-table-column prop="unit" align="center" show-overflow-tooltip label="单价"
                                min-width="160">
                                <template slot-scope="scope">
                                    <div class="table_input">
                                        <el-input @change="changeValues(scope.$index, scope.row)"
                                            :disabled="scope.row.isedit" placeholder="请输入内容" :min="0" type="number"
                                            v-model="scope.row.price" clearable></el-input>
                                    </div>
                                </template>
                            </el-table-column>

                            <el-table-column prop="taxRate" align="center" show-overflow-tooltip label="税率"
                                min-width="160">
                                <template slot-scope="scope">
                                    <div style="display: flex;align-items: center;justify-content: center;">
                                        <div class="table_input" style="width: 100px;">
                                            <el-input @change="changeValues(scope.$index, scope.row)"
                                                :disabled="scope.row.isedit" placeholder="请输入内容" :min="0" type="number"
                                                v-model="scope.row.taxRate" clearable>
                                            </el-input>
                                        </div>
                                        <div>%</div>
                                    </div>
                                </template>
                            </el-table-column>

                        </el-table>
                    </div>
                </div>
                <div class="but_box">
                    <el-button @click="orderdialogVisible = false" class="cancelClass">取消</el-button>
                    <el-button type="primary" @click="creatOrderBut" style="margin-left: 120px">提交</el-button>
                </div>
            </div>
        </el-dialog>
        <ul id="jq22" style="opacity: 0;height: 0;overflow: hidden;">
            <li v-for="(item, index) in previewList" :key="index"><img :src="item" /></li>
        </ul>
    </div>
    <script src="../js/FileSaver.js"></script>
    <script src="../js/public.js?123456"></script>
    <script>
        var layer = layui.layer
        var vm = new Vue({
            el: '#app',
            data() {
                return {
                    noorderHtObj: {
                        noorderHtId: '',
                        noorderHtName: '',
                    },
                    creatOrderList: [],
                    orderdialogVisible: false,
                    dialogVisible: false,
                    showApp: false,
                    projectId: '',
                    allIndex: '',
                    childIndex: '',
                    inputcpList: [{
                        uuid: '',
                        licensePlate: '',
                        pictureId: '',
                        pictureURL: '',
                    }],
                    childorderIndex: '',
                    popupType: 1,
                    noorderImgData: [],
                    companyId: '',
                    radio: '1',
                    input: '',
                    inputtypeImg: [],
                    contract: {
                        contractId: '',
                        contractName: ''
                    },
                    plan: {
                        planId: '',
                        planName: ''
                    },
                    supplier: {
                        supplierId: '',
                        supplierName: ''
                    },
                    remarks: '',
                    allTableData: [],
                    clmxList: [],
                    fileList: [],
                    glimgList: [],
                    listGlchioceImgData: [],
                    listGlinputImgData: [],
                    previewList: [],
                    // 添加进场单 提交按钮 请求锁
                    isOrderRequestFlag: false,
                    testNumber: 10,
                    // 单价和税率设置的小数点的位数
                    dotCount: 2,
                    // 添加进场单 请求flag
                    isRequestFlag: false
                };
            },
            methods: {
                // 校验单价金额税率
                validateNumber(value) {
                    // 校验小数点
                    if (this.checkDotNumber(value, this.dotCount)) {
                        value = parseFloat(value);
                        // 校验数字范围
                        if (value <= 0) {
                            this.$message({
                                message: '请输入大于0的数字',
                                type: 'warning',
                                duration: 1000
                            });
                            return false
                        } else if (value > 20) {
                            this.$message({
                                message: '请输入不大于20的数字',
                                type: 'warning',
                                duration: 1000
                            });
                            return false
                        } else {
                            return true
                        }
                    } else {
                        // 小数点校验不合格
                        var count = this.dotCount;
                        this.$message({
                            message: '小数点后的小数位数不超过于' + count,
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                },

                checkDotNumber(value, count) {
                    value = typeof value === "number" ? value + '' : value;
                    var dotIndex = value.indexOf(".") + 1;
                    var dotNumLength = value.length - dotIndex;
                    if (dotNumLength > count) {
                        return false
                    } else {
                        return true
                    }
                },

                validateTextNumber(value) {
                    // 校验小数点
                    if (this.checkDotNumber(value, this.dotCount)) {
                        value = parseFloat(value);
                        // 校验数字范围
                        if (value <= 0) {
                            this.$message({
                                message: '请输入大于0的数字',
                                type: 'warning',
                                duration: 1000
                            });
                            return
                        } else if (value > 20) {
                            this.$message({
                                message: '请输入不大于20的数字',
                                type: 'warning',
                                duration: 1000
                            });
                            return
                        }
                    } else {
                        // 小数点校验不合格
                        var count = this.dotCount;
                        this.$message({
                            message: '小数点后的小数位数不超过于' + count,
                            type: 'warning',
                            duration: 1000
                        });
                    }
                },
                // 无订单进场的材料需要选择一个合同或者输入单价
                creatOrderBut() {
                    var that = this
                    if (that.isRequestFlag) {
                        // 正在请求
                        return
                    }

                    for (var i = 0; i < this.creatOrderList.length; i++) {
                        // 对单价和税率进行校验
                        if (!this.creatOrderList[i].price || this.creatOrderList[i].price == 0) {
                            this.$message({
                                message: '请输入单价',
                                type: 'warning',
                                duration: 1000
                            });
                            return false
                        }
                        // 对税收进行校验
                        // if (!this.validateNumber(this.creatOrderList[i].taxRate)) {
                        //     return false
                        // }
                    }
                    var newArr = []
                    for (var i = 0; i < this.creatOrderList.length; i++) {
                        newArr.push({
                            oper: 'add',
                            manufacturerID: this.creatOrderList[i].manufacturerID,
                            // quantity: this.creatOrderList[i].count,
                            purchaseQuantity: this.creatOrderList[i].count,
                            price: this.creatOrderList[i].price,
                            taxRate: this.creatOrderList[i].taxRate,
                            arrivalTime: this.creatOrderList[i].approachTime,
                            materialName: this.creatOrderList[i].materialName,
                            materialId: this.creatOrderList[i].materialId,
                            specificationId: this.creatOrderList[i].specsId,
                            specificationName: this.creatOrderList[i].specsName,
                            unit: this.creatOrderList[i].unit,
                            storageId: this.creatOrderList[i].storageId,
                            goodsShelvesId: this.creatOrderList[i].goodsShelvesId,
                            goodsShelvesNumber: this.creatOrderList[i].goodsShelvesNumber,
                            supplierName: this.supplier.supplierName,
                            supplierId: this.supplier.supplierId,
                        })
                    }
                    that.isRequestFlag = true;
                    xLoading(true, '正在创建订单')
                    $.ajax({
                        type: 'post',
                        url: baseUrl + '/Material/SavePurchaseOrderDatas',
                        data: {
                            supplierName: that.supplier.supplierName,
                            supplierId: that.supplier.supplierId,
                            // suppilerId: that.noorderHtObj.suppilerId,
                            // supplierName: that.noorderHtObj.suppilerName,
                            contractId: that.noorderHtObj.noorderHtId,
                            contractName: that.noorderHtObj.noorderHtName,
                            jsonDatas: JSON.stringify(newArr)
                        },
                        dataType: 'json',
                        success: function (res) {
                            xLoading(false)
                            if (!res.success) {
                                that.$message({
                                    message: res.msg ? res.msg : '程序错误，请重试',
                                    type: 'error'
                                });
                                return false;
                            }
                            setTimeout(function () {
                                that.isRequestFlag = false;
                                that.confirms1(res.recid, res.orderNumber, 1)
                            }, 100)
                        }
                    });
                },
                changeValues(index, row) {
                    // 对税率和单价进行小数点控制 以及数量的控制

                    if (!!row.taxRate) {
                        row.taxRate = parseFloat(row.taxRate);
                        if (row.taxRate > 20) {
                            row.taxRate = 20
                        }
                        if (row.taxRate < 0) {
                            row.taxRate = 0
                        }
                        row.taxRate = row.taxRate.toFixed(2);

                    }

                    if (!!row.price) {// 单价
                        row.price = parseFloat(row.price);
                        if (row.price < 0) {
                            row.price = 0
                        }
                        row.price = row.price.toFixed(2);
                    }

                    // this.$set(this.creatOrderList, index, row)
                    // this.$forceUpdate()
                },
                changeValue(value) {
                    this.$forceUpdate()
                },
                chioceorderCpConfirm() {
                    if (this.inputcpList.length === 1 && this.inputcpList[0].uuid === "" && this.inputcpList[0].licensePlate === "" && this.inputcpList[0].pictureURL === "") {
                        this.dialogVisible = false
                        return
                    }
                    var uuidlicensePlates = []
                    var showCpValue = []
                    var uuidImgs = []
                    for (var i = 0; i < this.inputcpList.length; i++) {
                        uuidlicensePlates.push((this.inputcpList[i].uuid ? this.inputcpList[i].uuid : 0) + ',' + this.inputcpList[i].licensePlate)
                        showCpValue.push(this.inputcpList[i].licensePlate)
                        if (this.inputcpList[i].pictureId && this.inputcpList[i].pictureId != 0) {
                            this.listGlchioceImgData.push({
                                fileid: this.inputcpList[i].pictureId,
                                filename: '抓拍图片' + this.inputcpList[i].pictureId + '.png',
                                fileurl: this.inputcpList[i].pictureURL,
                                types: 'glList'
                            })
                        }
                        uuidImgs.push((this.inputcpList[i].uuid ? this.inputcpList[i].uuid : 0) + ',' + this.inputcpList[i].licensePlate + ',' + (this.inputcpList[i].pictureId ? this.inputcpList[i].pictureId : 0) + ',' + (this.inputcpList[i].pictureId ? this.inputcpList[i].pictureURL : 0))
                    }
                    this.clmxList[this.childorderIndex].uuidlicensePlates = uuidlicensePlates.join('|')
                    this.clmxList[this.childorderIndex].showCpValue = showCpValue.join(',')
                    this.clmxList[this.childorderIndex].uuidImgs = uuidImgs.join('|')
                    this.$forceUpdate()
                    this.dialogVisible = false
                },
                chioceCpConfirm() {
                    if (this.inputcpList.length === 1 && this.inputcpList[0].uuid === "" && this.inputcpList[0].licensePlate === "" && this.inputcpList[0].pictureURL === "") {
                        this.dialogVisible = false
                        return
                    }
                    var uuidlicensePlates = []
                    var showCpValue = []
                    var uuidImgs = []
                    for (var i = 0; i < this.inputcpList.length; i++) {
                        uuidlicensePlates.push((this.inputcpList[i].uuid ? this.inputcpList[i].uuid : 0) + ',' + this.inputcpList[i].licensePlate)
                        showCpValue.push(this.inputcpList[i].licensePlate)
                        if (this.inputcpList[i].pictureId && this.inputcpList[i].pictureId != 0) {
                            this.listGlchioceImgData.push({
                                fileid: this.inputcpList[i].pictureId,
                                filename: '抓拍图片' + this.inputcpList[i].pictureId + '.png',
                                fileurl: this.inputcpList[i].pictureURL,
                                types: 'glList'
                            })
                        }
                        uuidImgs.push((this.inputcpList[i].uuid ? this.inputcpList[i].uuid : 0) + ',' + this.inputcpList[i].licensePlate + ',' + (this.inputcpList[i].pictureId ? this.inputcpList[i].pictureId : 0) + ',' + (this.inputcpList[i].pictureId ? this.inputcpList[i].pictureURL : 0))
                    }
                    this.allTableData[this.allIndex].clmxList[this.childIndex].uuidlicensePlates = uuidlicensePlates.join('|')
                    this.allTableData[this.allIndex].clmxList[this.childIndex].showCpValue = showCpValue.join(',')
                    this.allTableData[this.allIndex].clmxList[this.childIndex].uuidImgs = uuidImgs.join('|')
                    this.$forceUpdate()
                    this.dialogVisible = false
                },
                bindCpImg(item) {
                    this.inputcpList[item].uuid = ''
                    this.inputcpList[item].pictureId = ''
                    this.inputcpList[item].pictureURL = ''
                    var that = this
                    var timeData = []
                    this.$forceUpdate()
                    timeData = [timeFormat(new Date(new Date().getTime() - 1 * 60 * 60 * 1000), 1), timeFormat(new Date(), 1)]
                    if (!that.inputcpList[item].licensePlate) {
                        return false
                    }
                    xLoading(true)
                    $.ajax({
                        type: 'post',
                        headers: {
                        },
                        url: baseUrl + '/Material/GetCarInfo',
                        data: {
                            inputLicensePlate: that.inputcpList[item].licensePlate,
                            startTime: timeData[0],
                            endTime: timeData[1]
                        },
                        dataType: 'json',
                        success: function (res) {
                            xLoading(false)
                            if (!res.success) {
                                return false;
                            }
                            if (!res.data) {
                                return false
                            }
                            that.inputcpList[item].uuid = res.data[0].uuid
                            that.inputcpList[item].pictureId = res.data[0].pictureId
                            that.inputcpList[item].pictureURL = res.data[0].pictureURL
                        }
                    });
                },
                xzCpimg() {
                    var that = this
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择车牌',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['77.91%', '98.88%'],
                        // area: ['91.91%', '72.16%'],
                        content: '/ApsPublic/publicList/jccpImgList.html?companyId=' + that.companyId + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    for (var i = 0; i < newList.length; i++) {
                                        that.inputcpList.push({
                                            uuid: newList[i].uuid,
                                            licensePlate: newList[i].licensePlate,
                                            pictureId: newList[i].pictureId,
                                            pictureURL: newList[i].pictureURL
                                        })
                                    }
                                    for (var i = 0; i < that.inputcpList.length; i++) {
                                        if (!that.inputcpList[i].licensePlate) {
                                            that.inputcpList.splice(i, 1)
                                        }
                                    }
                                }
                            }, 10)
                        }
                    });
                },
                addCpId(item) {
                    if (!item.licensePlate) {
                        return false
                    }
                    this.inputcpList.push({
                        uuid: '',
                        licensePlate: '',
                        pictureId: '',
                        pictureURL: ''
                    })
                },
                chiocenoorderCpss(row, index) {
                    var that = this
                    this.dialogVisible = true
                    this.childorderIndex = index
                    this.inputcpList = []
                    this.popupType = 2
                    if (row.uuidImgs) {
                        for (var i = 0; i < row.uuidImgs.split('|').length; i++) {
                            this.inputcpList.push({
                                uuid: row.uuidImgs.split('|')[i].split(',')[0],
                                licensePlate: row.uuidImgs.split('|')[i].split(',')[1],
                                pictureId: row.uuidImgs.split('|')[i].split(',')[2],
                                pictureURL: row.uuidImgs.split('|')[i].split(',')[3],
                            })
                        }
                    } else {
                        this.inputcpList.push({
                            uuid: '',
                            licensePlate: '',
                            pictureId: '',
                            pictureURL: '',
                        })
                    }
                },
                chioceCpss(item, row, index) {
                    var that = this
                    this.dialogVisible = true
                    this.allIndex = item
                    this.childIndex = index
                    this.popupType = 1
                    this.inputcpList = []
                    if (row.uuidImgs) {
                        for (var i = 0; i < row.uuidImgs.split('|').length; i++) {
                            this.inputcpList.push({
                                uuid: row.uuidImgs.split('|')[i].split(',')[0],
                                licensePlate: row.uuidImgs.split('|')[i].split(',')[1],
                                pictureId: row.uuidImgs.split('|')[i].split(',')[2],
                                pictureURL: row.uuidImgs.split('|')[i].split(',')[3],
                            })
                        }
                    } else {
                        this.inputcpList.push({
                            uuid: '',
                            licensePlate: '',
                            pictureId: '',
                            pictureURL: '',
                        })
                    }
                },
                chioceCj(item, row, index) {
                    var that = this
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择生产厂家',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['77.91%', '98.88%'],
                        // area: ['91.91%', '72.16%'],
                        content: '/ApsPublic/publicList/gysList.html?isSingle=1&companyId=' + that.companyId + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    row.manufacturerId = newList[0].id
                                    row.manufacturer = newList[0].name
                                    item.clmxList[index] = row
                                    that.$forceUpdate()
                                }
                            }, 10)
                        }
                    });
                },
                // 选择位置
                chioceCk(item, row, index) {
                    var that = this
                    var selectArr = []
                    var materiaobj = {}
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择仓库货架',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['77.91%', '98.88%'],
                        // area: ['91.91%', '72.16%'],
                        content: '/ApsPublic/publicList/ckList.html?isSingle=1&materiaobj=' + encodeURIComponent(JSON.stringify(materiaobj)) + '&projectId=' + that.projectId + '&selectArr=' + encodeURIComponent(JSON.stringify(selectArr)) + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    row.storageId = newList[0].id
                                    row.storageName = newList[0].name
                                    row.goodsShelvesNumber = newList[0].x_goodsShelvesNumber
                                    row.goodsShelvesId = newList[0].x_goodsShelvesId
                                    item.clmxList[index] = row
                                    that.$forceUpdate()
                                    // that.$set(that.clmxList, index, row)
                                }
                            }, 10)
                        }
                    });
                },
                // 选择位置
                chioceCk2(row, index) {
                    var that = this
                    var selectArr = []
                    for (var i = 0; i < this.clmxList.length; i++) {
                        selectArr.push({
                            id: this.clmxList[i].storageId,
                            number: this.clmxList[i].goodsShelvesNumber,
                        })
                    }
                    var materiaobj = {
                        materialId: row.materialId + '',
                        specsId: row.specificationId + ''
                    }
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择仓库货架',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['77.91%', '98.88%'],
                        // area: ['91.91%', '72.16%'],
                        content: '/ApsPublic/publicList/ckList.html?isSingle=1&materiaobj=' + encodeURIComponent(JSON.stringify(materiaobj)) + '&projectId=' + that.projectId + '&selectArr=' + encodeURIComponent(JSON.stringify(selectArr)) + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    row.storageId = newList[0].id
                                    row.storageName = newList[0].name
                                    row.goodsShelvesNumber = newList[0].x_goodsShelvesNumber
                                    row.goodsShelvesId = newList[0].x_goodsShelvesId
                                    that.$set(that.clmxList, index, row)
                                }
                            }, 10)
                        }
                    });
                },
                cancels() {
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                },
                // 点击提交按钮 先确认是否选择的项目 已经开始盘点
                confirms2() {
                    var that = this
                    xLoading(true, '正在校验')
                    $.ajax({
                        type: 'post',
                        headers: {
                        },
                        url: baseUrl + '/Material/GetProjectInventoryStatus',
                        data: {
                            // planId: that.plan.planId
                        },
                        dataType: 'json',
                        success: function (res) {
                            xLoading(false)
                            if (!res.success) {
                                that.$message({
                                    message: res.msg ? res.msg : '程序错误，请重试',
                                    type: 'error'
                                });
                                return false;
                            }
                            if (res.data == 1) {
                                that.$message({
                                    message: '盘点中，不可添加进场单',
                                    type: 'error'
                                });
                                return false
                            }
                            // 选择的项目中尚未开始盘点
                            // 如果盘点中的话 不可添加进场
                            if (that.clmxList.length > 0) {
                                // 存在无明细订单明细
                                that.creatOrder()
                            } else {
                                that.confirms1(null, null, 2)
                            }
                        }
                    });
                },
                // 当前项目尚未开始盘点 存在无明细订单订单明细 提交请求前  需要进行校验
                creatOrder() {
                    var that = this
                    if (this.supplier.supplierId.length == 0 || this.supplier.supplierId == 0) {
                        this.$message({
                            message: '请选择供应商',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    // if (this.glimgList.length == 0 && this.listGlchioceImgData.length == 0) {
                    //     this.$message({
                    //         message: '请选择或者上传现场抓拍',
                    //         type: 'warning',
                    //         duration: 1000
                    //     });
                    //     return false
                    // }

                    if (this.fileList.length == 0) {
                        this.$message({
                            message: '请上传送货单照片',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    var dataJson = []
                    // if (this.allTableData.length == 0) {
                    //     this.$message({
                    //         message: '请添加明细',
                    //         type: 'warning',
                    //         duration: 1000
                    //     });
                    //     return false
                    // }
                    for (var i = 0; i < this.allTableData.length; i++) {
                        dataJson.push({
                            purchaseOrderRecid: this.allTableData[i].recid,
                            purchaseOrderType: 1,
                            purchaseOrder: this.allTableData[i].orderNo,
                            buyPlanId: this.allTableData[i].buyPlanId,
                            purchaseMaterialDatas: this.allTableData[i].clmxList

                        })

                        // if (dataJson.length == 0) {
                        //     this.$message({
                        //         message: '请添加明细',
                        //         type: 'warning',
                        //         duration: 1000
                        //     });
                        //     return false
                        // }
                        // 校验是否已经选择仓库 存放位置  仓库字段为storageId
                        // 去掉是否选择仓库位置校验
                        // for (var i = 0; i < dataJson.length; i++) {
                        //     for (var j = 0; j < dataJson[i].purchaseMaterialDatas.length; j++) {
                        //         // if (!dataJson[i].purchaseMaterialDatas[j].uuidlicensePlates) {
                        //         //     this.$message({
                        //         //         message: '请选择订单明细进场车牌',
                        //         //         type: 'warning',
                        //         //         duration: 1000
                        //         //     });
                        //         //     return false
                        //         // }
                        //         if (!dataJson[i].purchaseMaterialDatas[j].storageId || dataJson[i].purchaseMaterialDatas[j].storageId == 0) {
                        //             this.$message({
                        //                 message: '请选择订单明细存放位置',
                        //                 type: 'warning',
                        //                 duration: 1000
                        //             });
                        //             return false
                        //         }
                        //     }
                        // }
                    }
                    for (var i = 0; i < dataJson.length; i++) {
                        if (dataJson[i].purchaseMaterialDatas.length > 0) {
                            for (var j = 0; j < dataJson[i].purchaseMaterialDatas.length; j++) {
                                if (!dataJson[i].purchaseMaterialDatas[j].count || parseInt(dataJson[i].purchaseMaterialDatas[j].count) === 0) {
                                    this.$message({
                                        message: '请选择订单明细的进场数量',
                                        type: 'warning',
                                        duration: 1000
                                    });
                                    return false
                                }
                                // if (!dataJson[i].purchaseMaterialDatas[j].storageId || dataJson[i].purchaseMaterialDatas[j].storageId == 0) {
                                //     this.$message({
                                //         message: '请选择订单明细存放位置',
                                //         type: 'warning',
                                //         duration: 1000
                                //     });
                                //     return false
                                // }
                            }
                        }
                    }
                    dataJson.push({
                        purchaseOrderRecid: '',
                        purchaseOrderType: 2,
                        purchaseOrder: '',
                        buyPlanId: '',
                        purchaseMaterialDatas: this.clmxList
                    })

                    for (var i = 0; i < this.clmxList.length; i++) {
                        // if (!this.clmxList[i].storageId || this.clmxList[i].storageId == 0) {
                        //     this.$message({
                        //         message: '无订单进场明细位置必须选择',
                        //         type: 'warning',
                        //         duration: 1000
                        //     });
                        //     return false
                        // }
                        if (this.clmxList[i].count == 0) {
                            this.$message({
                                message: '请输入无订单明细进场数量',
                                type: 'warning',
                                duration: 1000
                            });
                            return false
                        }
                        // if (!this.clmxList[i].uuidlicensePlates) {
                        //     this.$message({
                        //         message: '请选择无订单明细进场车牌',
                        //         type: 'warning',
                        //         duration: 1000
                        //     });
                        //     return false
                        // }
                    }
                    var arr = JSON.parse(JSON.stringify(this.clmxList))
                    for (var i = 0; i < arr.length; i++) {
                        arr[i].price = 0
                        arr[i].taxRate = 0
                        arr[i].isedit = false
                        arr[i].manufacturerID = that.supplier.supplierId
                        arr[i].manufacturer = that.supplier.supplierName
                    }
                    this.creatOrderList = arr;
                    this.$forceUpdate()

                    this.noorderHtObj = {
                        noorderHtId: '',
                        noorderHtName: '',
                        suppilerId: '',
                        suppilerName: ''
                    }
                    this.orderdialogVisible = true
                },
                chioceht() {
                    var newArr = []
                    var that = this
                    var materSpecList = [];
                    console.log(this.creatOrderList)
                    for (var i = 0; i < this.creatOrderList.length; i++) {
                        var item = (this.creatOrderList[i].materialId || "0") + "-" + (this.creatOrderList[i].specsId || "0");
                        materSpecList.push(item);
                    }

                    var materSpecListStr = encodeURIComponent(materSpecList.join(","));

                    for (var i = 0; i < this.creatOrderList.length; i++) {
                        newArr.push({
                            materialId: this.creatOrderList[i].materialId,
                            specificationId: this.creatOrderList[i].specsId,
                            materialName: this.creatOrderList[i].materialName,
                            specifiName: this.creatOrderList[i].specsName,
                            price: 0,
                            taxRate: 0,
                        })
                    }
                    console.log(materSpecListStr)
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择合同',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        // area: ['50.1%', '64.25%'],

                        area: ['91.91%', '72.16%'],
                        content: '/ApsPublic/publicList/cghtList.html?isSingle=1&isjccreatorder=1&creatClId=' + encodeURIComponent(JSON.stringify(newArr)) + '&supplierId=' + this.supplier.supplierId + '&isSelect=1&materSpecList=' + materSpecListStr + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {

                                    var newList = JSON.parse(parent.$('#publicValue').val()).list;
                                    var info = JSON.parse(parent.$('#publicValue').val()).info;
                                    var prevList = that.creatOrderList;
                                    for (var i = 0; i < newList.length; i++) {
                                        var curNewItem = newList[i];
                                        for (var j = 0; j < prevList.length; j++) {
                                            var curPrevItem = prevList[j];

                                            if (curPrevItem.materialId === curNewItem.materialId && curPrevItem.specsId === curNewItem.specificationId) {

                                                curPrevItem.price = curNewItem.price;
                                                curPrevItem.taxRate = curNewItem.taxRate;
                                                curPrevItem.manufacturer = curNewItem.manufacturer;
                                                curPrevItem.manufacturerID = curNewItem.manufacturerId;
                                                curPrevItem.isedit = false;
                                            }
                                        }
                                    }


                                    // for (var j = 0; j < that.creatOrderList.length; j++) {
                                    //     for (var i = 0; i < newList.list.length; i++) {
                                    //         if (newList.list[i].materialId == that.creatOrderList[j].materialId && newList.list[i].specsId == that.creatOrderList[j].specificationId) {
                                    //             var rows = that.creatOrderList[j]
                                    //             rows.price = newList.list[i].price
                                    //             rows.taxRate = newList.list[i].taxRate
                                    //             rows.isedit = true
                                    //             rows.manufacturerID = newList.info.suppilerId
                                    //             rows.manufacturer = newList.info.suppilerId
                                    //             that.$set(that.creatOrderList, j, rows)
                                    //         }
                                    //     }
                                    // }

                                    that.noorderHtObj = {
                                        noorderHtId: info.id,
                                        noorderHtName: info.name,
                                        suppilerId: info.suppilerId,
                                        suppilerName: info.suppilerName
                                    }
                                    console.log(info, 444)
                                    that.$forceUpdate()
                                }
                            }, 10)
                        }
                    });
                },
                // 没有提交 无订单进场明细 需要订单明细不为空
                confirms1(orderrecid, orderNo, type) {
                    //1 无订单进场明细 2 有订单明细

                    var that = this
                    if (this.supplier.supplierId.length == 0 || this.supplier.supplierId == 0) {
                        this.$message({
                            message: '请选择供应商',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    // if (this.glimgList.length == 0 && this.listGlchioceImgData.length == 0) {
                    //     this.$message({
                    //         message: '请选择或者上传现场抓拍',
                    //         type: 'warning',
                    //         duration: 1000
                    //     });
                    //     return false
                    // }

                    if (this.fileList.length == 0) {
                        this.$message({
                            message: '请上传送货单照片',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    var dataJson = []
                    if (this.allTableData.length == 0 && type === 2) {
                        this.$message({
                            message: '请添加订单明细',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    for (var i = 0; i < this.allTableData.length; i++) {
                        dataJson.push({
                            purchaseOrderRecid: this.allTableData[i].recid,
                            purchaseOrderType: 1,
                            purchaseOrder: this.allTableData[i].orderNo,
                            buyPlanId: this.allTableData[i].buyPlanId,
                            purchaseMaterialDatas: this.allTableData[i].clmxList

                        })
                        // if (dataJson.length == 0) {
                        //     this.$message({
                        //         message: '请添加订单明细',
                        //         type: 'warning',
                        //         duration: 1000
                        //     });
                        //     return false
                        // }
                        for (var i = 0; i < dataJson.length; i++) {
                            if (dataJson[i].purchaseMaterialDatas.length > 0) {
                                for (var j = 0; j < dataJson[i].purchaseMaterialDatas.length; j++) {
                                    if (!dataJson[i].purchaseMaterialDatas[j].count || parseInt(dataJson[i].purchaseMaterialDatas[j].count) === 0) {
                                        this.$message({
                                            message: '请选择订单明细的进场数量',
                                            type: 'warning',
                                            duration: 1000
                                        });
                                        return false
                                    }
                                    // if (!dataJson[i].purchaseMaterialDatas[j].storageId || dataJson[i].purchaseMaterialDatas[j].storageId == 0) {
                                    //     this.$message({
                                    //         message: '请选择订单明细存放位置',
                                    //         type: 'warning',
                                    //         duration: 1000
                                    //     });
                                    //     return false
                                    // }
                                }
                            }
                        }
                    }
                    if (dataJson.length == 0 && type === 2) {
                        this.$message({
                            message: '请添加明细',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    // for (var i = 0; i < this.clmxList.length; i++) {
                    //     if (!this.clmxList[i].storageId || this.clmxList[i].storageId == 0) {
                    //         this.$message({
                    //             message: '无订单进场明细位置必须选择',
                    //             type: 'warning',
                    //             duration: 1000
                    //         });
                    //         return false
                    //     }
                    // }
                    if (this.clmxList.length > 0) {
                        var newArr = []
                        for (var i = 0; i < this.creatOrderList.length; i++) {
                            newArr.push({
                                oper: 'add',
                                manufacturerId: this.creatOrderList[i].manufacturerID,
                                manufacturer: this.creatOrderList[i].manufacturer,
                                count: this.creatOrderList[i].count,
                                price: this.creatOrderList[i].price,
                                taxRate: this.creatOrderList[i].taxRate,
                                approachTime: this.creatOrderList[i].approachTime,
                                materialName: this.creatOrderList[i].materialName,
                                materialId: this.creatOrderList[i].materialId,
                                specsId: this.creatOrderList[i].specsId,
                                specsName: this.creatOrderList[i].specsName,
                                unit: this.creatOrderList[i].unit,
                                storageId: this.creatOrderList[i].storageId,
                                goodsShelvesId: this.creatOrderList[i].goodsShelvesId,
                                goodsShelvesNumber: this.creatOrderList[i].goodsShelvesNumber,
                                uuidlicensePlates: this.creatOrderList[i].uuidlicensePlates,
                            })
                        }
                        dataJson.push({
                            purchaseOrderRecid: orderrecid,
                            purchaseOrderType: 1,
                            purchaseOrder: orderNo,
                            buyPlanId: '',
                            purchaseMaterialDatas: newArr
                        })
                    }
                    var pictureURL = []
                    var pictureId = []
                    var pictureUploadId = []
                    for (var i = 0; i < this.fileList.length; i++) {
                        pictureURL.push(this.fileList[i].fileid + ',' + this.fileList[i].filename + ',' + this.fileList[i].userName + ',' + this.fileList[i].uploadTime)
                    }
                    for (var i = 0; i < this.glimgList.length; i++) {
                        if (this.glimgList[i].types == 'upload') {
                            pictureUploadId.push(this.glimgList[i].fileid + ',' + this.glimgList[i].filename)
                        }
                        if (this.glimgList[i].types == 'glList') {
                            pictureId.push(this.glimgList[i].fileid)
                        }
                    }
                    for (var i = 0; i < this.listGlchioceImgData.length; i++) {
                        pictureId.push(this.listGlchioceImgData[i].fileid)
                    }
                    // 提交请求前 校验通过
                    if (that.isOrderRequestFlag) {
                        // 正在请求
                        return
                    } else {
                        that.isOrderRequestFlag = true;
                        xLoading(true, '正在提交')
                        $.ajax({
                            type: 'post',
                            headers: {
                            },
                            url: baseUrl + '/Material/SaveApproachMatrtialData',
                            data: {
                                contractId: that.contract.contractId,
                                planId: that.plan.planId,
                                contractName: that.contract.contractName,
                                planName: that.plan.planName,
                                supplierName: that.supplier.supplierName,
                                supplierId: that.supplier.supplierId,
                                remarks: that.remarks,
                                isDetails: 1,
                                deliveryNotePic: pictureURL.join('|'),
                                approachCapturePic_Join: pictureId.join('|'),
                                approachCapturePic_Upload: pictureUploadId.join('|'),
                                dataJson: JSON.stringify(dataJson)
                            },
                            dataType: 'json',
                            success: function (res) {
                                xLoading(false)
                                if (!res.success) {
                                    that.$message({
                                        message: res.msg ? res.msg : '程序错误，请重试',
                                        type: 'error'
                                    });
                                    return false;
                                }
                                that.$message({
                                    message: '已提交',
                                    type: 'success'
                                });
                                setTimeout(function () {
                                    that.isOrderRequestFlag = false;
                                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                    parent.layer.close(index);
                                }, 500)
                            },
                            error: function (res) {
                                that.isOrderRequestFlag = false;
                            }
                        });
                    }
                },
                radioChange() {
                    this.contract = {
                        contractId: '',
                        contractName: ''
                    }
                    this.plan = {
                        planId: '',
                        planName: ''
                    }
                    this.supplier = {
                        supplierId: '',
                        supplierName: ''
                    }
                },
                prevewImg(urls) {
                    this.previewList = [urls];
                    setTimeout(function () {
                        var viewer = new Viewer(document.getElementById('jq22'), {
                            hide: function () {
                                viewer.destroy();
                            }
                        });
                        viewer.show();
                    }, 10);
                },
                downImg(filename, urls) {
                    publicdownFile(filename, urls)
                },
                removeImg(arr, index, types) {
                    var title = '此操作将永久删除该文件, 是否继续?'
                    if (types == 1) {
                        title = '此操作将永久删除该数据, 是否继续?'
                    }
                    this.$confirm(title, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        arr.splice(index, 1)
                    }).catch(function () {
                    });
                },
                // 送货单上传
                shdhttprequest(file) {
                    this.uploadImg(file, 2)
                },
                // 抓拍上传
                zphttprequest(file) {
                    this.uploadImg(file, 1)
                },
                uploadImg(file, types) {
                    var that = this
                    if (getFileType(file.file.name) != 'IMG') {
                        this.$message({
                            message: '只能上传图片',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    xLoading(true, '正在上传')
                    var formData = new FormData();
                    formData.append('files', file.file);
                    $.ajax({
                        type: 'post',
                        url: baseUrl + '/Common/UploadFile?method=UploadFile&type=OSS',
                        data: formData,
                        dataType: 'json',
                        contentType: false,
                        processData: false,
                        success: function (res) {
                            xLoading(false)
                            if (!res.success) {
                                that.$message({
                                    message: res.msg,
                                    type: 'error'
                                });
                                return false;
                            }
                            var newobj = {
                                fileid: res.data.fileId,
                                filename: res.data.fileName,
                                fileurl: res.data.ossUrl,
                                uploadTime: res.data.uploadTime,
                                userName: res.data.userName,
                                types: 'upload'
                            }
                            if (types == 1) {
                                that.glimgList.push(newobj)
                            }
                            if (types == 2) {
                                that.fileList.push(newobj)
                            }
                        }
                    });
                },
                // 选择关联照片
                chioceGlimg() {
                    var that = this
                    var selectArr = []
                    for (var i = 0; i < this.glimgList.length; i++) {
                        if (this.glimgList[i].types == 'glList') {
                            selectArr.push({
                                id: this.glimgList[i].fileid
                            })
                        }
                    }
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '关联抓拍',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['55.62%', '68.61%'],
                        content: '/ApsPublic/publicList/imgList.html?projectId=' + that.projectId + '&selectArr=' + encodeURIComponent(JSON.stringify(selectArr)) + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    for (var j = 0; j < that.glimgList.length; j++) {
                                        for (var i = 0; i < newList.length; i++) {
                                            if (newList[i].id == that.glimgList[j].id) {
                                                if (that.glimgList[j].types == 'glList') {
                                                    newList.splice(i, 1)
                                                }
                                            }
                                        }
                                    }
                                    for (var i = 0; i < newList.length; i++) {
                                        that.glimgList.push({
                                            fileid: newList[i].id,
                                            filename: '抓拍图片' + newList[i].id + '.png',
                                            fileurl: newList[i].url,
                                            types: 'glList'
                                        })
                                    }
                                }
                            }, 10)
                        }
                    });
                },
                // 选择采购合同
                chioceCght() {
                    var that = this
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择采购合同',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['60%', '77.77%'],
                        content: '/ApsPublic/publicList/cghtList.html?isSingle=1&projectId=' + that.projectId + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    that.contract = {
                                        contractId: newList[0].id,
                                        contractName: newList[0].title
                                    }
                                    that.supplier = {
                                        supplierId: newList[0].suppilerId,
                                        supplierName: newList[0].suppilerName
                                    }
                                }
                            }, 10)
                        }
                    });
                },
                // 选择采购计划
                chioceCgjh() {
                    var that = this
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择采购计划',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['33.33%', '77.77%'],
                        content: '/ApsPublic/publicList/cgjhList.html?isSingle=1&projectId=' + that.projectId + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    that.plan = {
                                        planId: newList[0].id,
                                        planName: newList[0].title
                                    }
                                }
                            }, 10)
                        }
                    });
                },
                // 选择供应商
                chioceGys() {
                    var that = this
                    if (that.supplier.supplierId.length > 0 && that.supplier.supplierId > 0) {
                        this.$confirm('是否更改供应商', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            parent.$('#publicValue').val('')
                            parent.layer.open({
                                type: 2,
                                title: '选择供应商',
                                shadeClose: true,
                                shade: 0.4,
                                skin: 'popup_layui',
                                area: ['60%', '77.77%'],
                                content: '/ApsPublic/publicList/gysList.html?isSingle=1&companyId=' + that.companyId + '&' + new Date().getTime(),
                                end: function () {
                                    setTimeout(function () {
                                        if (parent.$('#publicValue').val()) {
                                            var newList = JSON.parse(parent.$('#publicValue').val())
                                            that.supplier = {
                                                supplierId: newList[0].id,
                                                supplierName: newList[0].name
                                            }

                                        }
                                    }, 10)
                                }
                            });
                        }).catch(function () {
                        });
                        return false
                    }
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择供应商',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['60%', '77.77%'],
                        content: '/ApsPublic/publicList/gysList.html?isSingle=1&companyId=' + that.companyId + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    that.supplier = {
                                        supplierId: newList[0].id,
                                        supplierName: newList[0].name
                                    }
                                    that.allTableData = []
                                }
                            }, 10)
                        }
                    });
                },

                // 选择订单
                chioceorder() {
                    var that = this
                    if (that.supplier.supplierId.length == 0 || that.supplier.supplierId == 0) {
                        this.$message({
                            message: '请选择供应商',
                            type: 'warning',
                            duration: 1000
                        });
                        return false
                    }
                    var selectArr = []
                    for (var i = 0; i < this.allTableData.length; i++) {
                        selectArr.push({
                            recid: this.allTableData[i].recid,
                            orderNo: this.allTableData[i].orderNo
                        })
                    }
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择订单',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['91.91%', '72.16%'],
                        content: '/ApsPublic/publicList/cgddList.html?supplierId=' + that.supplier.supplierId + '&projectId=' + that.projectId + '&selectArr=' + encodeURIComponent(JSON.stringify(selectArr)) + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())

                                    var list = []
                                    for (var i = 0; i < newList.list.length; i++) {
                                        list.push({
                                            oper: 'add',
                                            isAdd: true,
                                            approachTime: timeFormat(new Date(), 1),
                                            materialId: newList.list[i].materialID,
                                            materialName: newList.list[i].materialName,
                                            specsId: newList.list[i].specificationId,
                                            specsName: newList.list[i].specificationName,
                                            unit: newList.list[i].unit,
                                            storageId: newList.list[i].warehouseId,
                                            storageName: newList.list[i].warehouseName,
                                            goodsShelvesId: newList.list[i].goodsShelvesId,
                                            goodsShelvesNumber: newList.list[i].goodsShelvesNumber,
                                            count: newList.list[i].approachQuantity,
                                            manufacturer: that.supplier.supplierName,
                                            manufacturerId: that.supplier.supplierId,
                                            uuidlicensePlates: '',
                                            showCpValue: ''
                                        })
                                    }
                                    that.allTableData.push({
                                        orderNo: newList.info.orderNo,
                                        recid: newList.info.recid,
                                        clmxList: list,
                                        buyPlanId: newList.info.buyPlanId
                                    })
                                }
                            }, 10)
                        }
                    });
                },
                // 新增材料明细
                chioceClmx() {
                    var that = this
                    var selectArr = []
                    for (var i = 0; i < this.clmxList.length; i++) {
                        selectArr.push({
                            materialId: this.clmxList[i].materialId,
                            specificationId: this.clmxList[i].specsId
                        })
                    }
                    parent.$('#publicValue').val('')
                    parent.layer.open({
                        type: 2,
                        title: '选择材料明细',
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'popup_layui',
                        area: ['52.08%', '64.81%'],
                        content: '/ApsPublic/publicList/clmxList.html?projectId=' + that.projectId + '&selectArr=' + encodeURIComponent(JSON.stringify(selectArr)) + '&' + new Date().getTime(),
                        end: function () {
                            setTimeout(function () {
                                if (parent.$('#publicValue').val()) {
                                    var newList = JSON.parse(parent.$('#publicValue').val())
                                    for (var i = 0; i < newList.length; i++) {
                                        that.clmxList.push({
                                            oper: 'add',
                                            isAdd: true,
                                            materialId: newList[i].materialId,
                                            materialName: newList[i].materialName,
                                            specsId: newList[i].specificationId,
                                            specsName: newList[i].specificationName,
                                            unit: newList[i].unit,
                                            storageId: '',
                                            storageName: '',
                                            goodsShelvesNumber: '',
                                            count: 0,
                                            approachTime: timeFormat(new Date(), 1),
                                            uuidlicensePlates: '',
                                            showCpValue: ''
                                        })
                                    }
                                }
                            }, 10)
                        }
                    });
                }
            },
            mounted() {
                var that = this
                this.showApp = true;
                this.projectId = getQuerys('projectId')
                this.companyId = getQuerys('companyId')
                // if (getQuerys('htObj')) {
                //     var htObj = JSON.parse(decodeURIComponent(getQuerys('htObj')))
                //     that.radio = '2'
                //     that.contract = {
                //         contractId: htObj.contractId ? htObj.contractId : '',
                //         contractName: htObj.contractName ? htObj.contractName : ''
                //     }
                //     that.supplier = {
                //         supplierId: htObj.supplierId ? htObj.supplierId : '',
                //         supplierName: htObj.supplierName ? htObj.supplierName: ''
                //     }
                // }
            }
        });
    </script>
</body>
<style>
    .page-container {
        padding-bottom: 70px;
        position: relative;
    }

    .but_box {
        position: absolute;
        left: 0;
        bottom: 0;
    }

    .top_box {
        overflow: hidden;
        width: 100%;
        padding: 0 3.34vw;
        padding-top: 1.56vh;
    }

    .contetn_box {
        width: 100%;
        height: 100%;
        overflow: auto;
    }

    .cell_box {
        float: left;
        padding-bottom: 20px;
    }

    .cell_title {
        display: flex;
        align-items: center;
        padding: 10px 0;
        height: 52px;
    }

    .cell_but {
        padding-left: 10px;
    }

    .cell_cont {
        overflow: auto;
        padding: 2.77vh 2.08vw;
        border: 1px solid #EBEBEB;
    }

    .form_box {
        display: flex;
        width: 100%;
        margin-top: 20px;
    }

    .form_name {
        line-height: 32px;
        width: 94px;
        min-width: 94px;
        padding-right: 10px;
        text-align: right;
    }

    .form_cont {
        display: flex;
        align-items: center;
        line-height: 1;
        flex: 1;
        flex-wrap: wrap;
    }

    .el-radio {
        margin-right: 2.51vw;
        line-height: 32px;
    }

    .el-input.is-disabled .el-input__inner {
        background: #fff;
        color: #333333;
        border: 1px solid #BBBBC5;
    }

    .el-textarea__inner {
        /* background: #FAFBFC; */
        border: 1px solid #BBBBC5;
    }

    .file_item {
        margin-left: 20px;
        margin-top: 20px;
        width: 140px;
        height: 140px;
        overflow: hidden;
        border-radius: 5px;
        float: left;
        position: relative;
    }

    .el-upload--picture-card {
        width: 100%;
        height: 100%;
        border-color: #D6D6D6;
        background: #FAFBFC;
    }

    .file_item>div {
        width: 100%;
        height: 100%;
    }

    .file_mask {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        transition: opacity 0.5s;
    }

    .file_mask>div {
        font-size: 22px;
        color: #fff;
        cursor: pointer;
    }

    .file_item:hover .file_mask {
        opacity: 1;
    }

    .txt_link>span {
        text-decoration: underline;
    }

    .public_popup_box {
        height: 100%;
    }

    .public_popup_cell_box {
        padding: 2.77vh 2.08vw 0;
        height: calc(100% - 70px);
        overflow: auto;
    }

    .public_popup {
        height: 70vh;
        margin-top: 15vh !important;
    }

    .popup_cell_item {
        margin-bottom: 20px;
    }

    .popup_cell_name {
        width: 122px;
        padding-right: 10px;
        text-align: right;
        line-height: 32px;
    }

    .popup_cell_cont {
        padding-right: 100px;
        display: flex;
        align-items: center;
        flex: 1;
    }

    .creat_order_box {
        display: flex;
        align-items: center;
    }

    .creat_order_table {
        height: calc(100% - 32px);
        padding-top: 10px;
        padding-bottom: 10px;
    }
</style>

</html>